export const mixin = {
    methods: {
        //时间戳处理 yy-mm-dd
        timeDetal(date) {
            // 后台返回的时间戳
            var format = "",
                oY = "",
                oM = "",
                oD = "";
            var oDate = new Date(date);
            oY = oDate.getFullYear();
            oM = oDate.getMonth() + 1;
            oM = oM < 10 ? "0" + oM : oM;
            oD = oDate.getDate();
            oD = oD < 10 ? "0" + oD : oD;
            format = oY + "-" + oM + "-" + oD;
            return format;
        },
        //时间戳处理 yy-mm-dd hh:mm:ss
        formatDate(time) {
            let date = new Date(time);
            var YY = date.getFullYear() + '-';
            var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
            var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
            var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
            var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
            return YY + MM + DD + " " + hh + mm + ss;

        },
        // 查看博客详情
        details(article_id) {
            this.$router.push({
                name: "BlogDetails",
                query: {
                    itemid: article_id,
                },
            });

        },
        //点击关注
        getAttention(uid) {
            this.$http({
                methods: "post",
                url: "user/userAttentionOther",
                params: {
                    user_id: uid, //被关注用户id
                },
            }).then(({
                data
            }) => {
                console.log(data);
                if (data.flag) {
                    this.$message.success("关注成功！");
                    this.isAttention = false;
                } else {
                    this.$message.error("关注失败！");
                }
            });
        },
        //取消关注
        cancelAttention(uid) {
            this.$http({
                methods: "post",
                url: "user/userUnAttentionOther",
                params: {
                    user_id: uid, //博客id
                },
            }).then(({
                data
            }) => {
                if (data.flag) {
                    this.$message.success("取消关注成功！");
                    this.isAttention = true;
                } else {
                    this.$message.error("取消关注失败！");
                }
            });
        },
        //关注回显
        showAttentionStatus(uid) {
            this.$http({
                methods: "post",
                url: "user/showAttentionStatus",
                params: {
                    user_id: uid, //博客id
                },
            }).then(({
                data
            }) => {
                console.log('关注回显', data);
                if (data.flag) {
                    this.isAttention = false;
                } else {
                    this.isAttention = true;
                }
            });
        },
        //websocket 开始连接时触发
        // handleWsOpen(e) {
        //     console.log("WebSocket open", e);
        //     this.$ws.send(
        //         "online" +
        //         JSON.parse(sessionStorage.getItem("LoginMessage")).message.uid
        //     );
        //     console.log("开始链接open");
        // },
        // // websocket 关闭时触发
        // handleWsClose(e) {
        //     console.log("WebSocket close", e);
        //     console.log("关闭链接close");
        // },
        // //websocket 出错时触发
        // handleWsError(e) {
        //     console.log("WebSocket error", e);
        // },
        // //websocket 接收数据时触发
        // handleWsMessage(e) {
        //     console.log("WebSocket message", e);

        // },
    }
}